package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.ProductInfo;
import cn.wolfcode.crm.mapper.ProductInfoMapper;
import cn.wolfcode.crm.query.PageResult;
import cn.wolfcode.crm.query.ProductInfoQueryObject;
import cn.wolfcode.crm.service.IProductInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductInfoServiceImpl implements IProductInfoService{
    @Autowired
    private ProductInfoMapper productInfoMapper;

    public int deleteByPrimaryKey(Long id) {
        return productInfoMapper.deleteByPrimaryKey(id);
    }

    public int insert(ProductInfo record) {

        return productInfoMapper.insert(record);
    }

    public ProductInfo selectByPrimaryKey(Long id) {
        return productInfoMapper.selectByPrimaryKey(id);
    }

    public List<ProductInfo> selectAll() {
        return productInfoMapper.selectAll();
    }

    public int updateByPrimaryKey(ProductInfo record) {
        return productInfoMapper.updateByPrimaryKey(record);
    }

    //分页
    public PageResult query(ProductInfoQueryObject qo){
        //查总数
        int total = productInfoMapper.queryForCount(qo);
        if(total==0){
            return new PageResult();
        }
        //查每页数据
        List<ProductInfo> rows = productInfoMapper.queryForList(qo);

        return new PageResult(rows,total);
    }
    //查产品状态
    public void changeState(Long id) {
        productInfoMapper.changeState(id);
    }
    //查产品不计免赔
    public void changeDeduction(Long id) {
        productInfoMapper.changeDeduction(id);
    }

    public List<ProductInfo> selectNameByAgencyId(Long id) {
        return productInfoMapper.selectNameByAgencyId(id);
    }

    public List<ProductInfo> selectByAgencyId(Long agencyId) {
        return productInfoMapper.selectByAgencyId(agencyId);
    }

}
